﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace DupeFilter
{
    /// <summary>
    /// Interaction logic for DirectoryTextBox.xaml
    /// </summary>
    public partial class DirectoryTextBox : UserControl
    {
        public string Path
        {
            get
            {
                if (Directory.Exists(txtPath.Text))
                {
                    return txtPath.Text;
                }
                else
                {
                    return string.Empty;
                }
            }
        }

        public DirectoryTextBox()
        {
            InitializeComponent();
        }

        private void txtPath_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (Directory.Exists(txtPath.Text))
            {
                txtPath.Foreground = Brushes.Black;
            }
            else
            {
                txtPath.Foreground = Brushes.Red;
            }
        }

        private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
            fbd.ShowDialog();
            if (fbd.SelectedPath != string.Empty)
            {
                txtPath.Text = fbd.SelectedPath;
            }
        }
    }
}
